<template>
    <div>
        <home-header></home-header>
        <home-swiper :list = 'swiperlist'></home-swiper>
        <home-icons :list = 'iconslist'></home-icons>
        <home-recommend :list = 'recommendlist'></home-recommend>
        <home-weekend :list = 'weekendlist'></home-weekend>
    </div>
</template>

<script>
/* eslint-disable */
import homeHeader from './compinents/header'
import homeSwiper from './compinents/swiper'
import homeIcons from './compinents/icons'
import homeRecommend from './compinents/recommend'
import homeWeekend from './compinents/weekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default{
    name: 'home',
    components: {
        homeHeader,
        homeSwiper,
        homeIcons,
        homeRecommend,
        homeWeekend
    },
    data() {
        return {
            lastCity: '',
            swiperlist : [],
            iconslist : [],
            recommendlist: [],
            weekendlist: []
        }
    },
    methods: {
        getHomeInfo () {
            axios.get('/api/index.json?city=' + this.city).then(this.getHomeInfoSucc)
        },
        getHomeInfoSucc(res){
            res = res.data
            if(res.ret && res.data){
                const data = res.data
                this.swiperlist = data.swiperList,
                this.iconslist = data.iconList,
                this.recommendlist = data.recommendList,
                this.weekendlist = data.weekendList
            }
        }
    },
    computed: {
        ...mapState(['city'])
    },
    mounted() {
        this.lastCity = this.city
        this.getHomeInfo()
    },
    activated() {
        if(this.lastCity !== this.city){
            this.lastCity = this.city
            this.getHomeInfo()
        }
    }
}
</script>


<style>

</style>
